// pages/myself/myappointment.js

var util = require('../../utils/util.js');
const app = getApp()
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listInfo: [],
    orderlists: [],
    planlists: [],
    loading: true,
    userinfo: '',
    showModalStatus: false,
    animationData: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    page = 1;
    if (!app.globalData.isLoginAuth) {
      this.showModal();
    }
  },

  /**
     * 生命周期函数--监听页面初次渲染完成
     */
  onReachBottom: function () {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (e) {
    if (app.globalData.isLoginAuth) {
      this.setData({
        listInfo: app.globalData.listInfo
      })
      this.getAppointlist();
    }
  },
  getAppointlist:function(){
    var that = this;
    var uid = wx.getStorageSync('userId');
    wx.request({
        url: app.globalData.hostUrl + 'member/appointmentUser',
      data: {
        uid:uid
      },
      methods: 'GET',
      header: {
        "Content-Type": "json"
      },
      success: function (res) {
        console.log(res);
        if (res.data.result) {
          that.setData({
            orderlists: res.data.result.lists,
            planlists: res.data.result.plxc
          });
        }
        else {
          that.setData({
            loading: false
          })
          return false
        }
      }
    })
  },
  calling: function (e) {
      var mobile = e.currentTarget.dataset.phone;
      wx.makePhoneCall({
          phoneNumber: mobile,
          success: function () {
              //console.log("拨打电话成功！")
          },
          fail: function () {
              // console.log("拨打电话失败！")
          }
      })
  },
  modifyfinish: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.oid;
    var cf = e.currentTarget.dataset.cf;
    var finish =2;
    var tipstr ='您确定完成次订单吗?';
    if (cf =='buy'||cf=='sell'){
      finish = e.currentTarget.dataset.finish;
      if (finish==2)
        tipstr='请确认销售员是否已提供看车服务？';
      else if(finish==3){
        tipstr = '请确认销售员是否已提供购车服务？';
      }  
    }
    wx.showModal({
      content: tipstr,
      showCancel: true,
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.hostUrl + 'member/modifyfinish',
            data: {
              flag: cf,
              fval: finish,
              id: id
            },
            methods: 'GET',
            success: function (res) {
              if (res.data.code == 200) {
                that.setData({
                  isshow: true
                })
                wx.navigateTo({
                  url: '../myself/myappointment',
                })
              }
              else {
                wx.showToast({
                  title: '操作失败',
                  icon: 'error',
                  duration: 2000
                })
              }
            }
          })
        }
      }
    });
  },
  goorderdetail: function (e) {
    var rid = e.currentTarget.dataset.id;
    var cf = e.currentTarget.dataset.cf;
    if (cf == 'xc') {
      var gotourl = '../xuecar/orderdetail?oid=' + rid;
    }
    else if (cf == 'pl') {
      var gotourl = '../traincar/orderdetail?oid=' + rid;
    }
    else if (cf == 'kp') {
      var gotourl = '../keepcar/orderdetail?oid=' + rid;
    }
    else if (cf == 'buy') {
      var gotourl = '../autocar/orderdetail?oid=' + rid;
    }
    else if (cf == 'sell') {
      var gotourl = '../autocar/ordselldetail?oid=' + rid;
    }
    wx.navigateTo({
      url: gotourl
    })
  },
  gohome: function () {
    wx.redirectTo({
      url: '../index/index',
    })
  },
  yuy: function () {
    if (1 == wx.getStorageSync('roleidentity')) {
      wx.redirectTo({
        url: '../myself/thappointment',
      })
    }
    else {
      wx.redirectTo({
        url: '../myself/myappointment',
      })
    }
  },
  orders: function () {
    if (1 == wx.getStorageSync('roleidentity')) {
      wx.redirectTo({
        url: '../myself/trorder',
      })
    }
    else {
      wx.redirectTo({
        url: '../myself/myorder',
      })
    }
  },
  mys: function () {
    wx.redirectTo({
      url: '../myself/myself',
    })
  },
  showModal: function () {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "ease-in-out",
      delay: 0
    })
    this.animation = animation
    animation.translateY(500).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  hideModal: function () {
    this.setData({
      showModalStatus: false,
    })
  },
  bindGetUserInfo: function (e) {
    console.log(e);
    if (e.detail.errMsg == 'getUserInfo:ok') {
      app.globalData.userInfo = e.detail.userInfo;
      app.getfansinfo();
    }
    else {
      wx.redirectTo({
        url: '../index/index',
      })
    }
  }
})